 import axios from 'axios'
 import { getToken } from '@/utils/auth.js';
 const request = axios.create({
    baseURL:'http://localhost:8080',
    timeout:30000
 })


 //request拦截器
 request.interceptors.request.use(config =>{
    config.headers['Content-Type'] = 'application/json;charset=utf-8';
    config.headers['token'] = getToken();
     config.headers['Authorization'] = 'Bearer ' + getToken()
    return config
 },error=>{
    console.error('request error:'+error)
    return Promise.reject(error)
 });

request.interceptors.response .use(
    response =>{
    let res=response.data;
    if(typeof res==='string'){
        res = res?JSON.parse(res):res
    }
    return res
 },error=>{
    console.error('response error:'+error)
    return Promise.reject(error)
 });

 export default request